home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu718.dms / pu718.adf / Hyper.help / help.c < prev    next >
C/C++ Source or Header  |  1994-10-04  |  7KB  |  208 lines

  1. /*******************  help.c  ********************
  2.  *                                               *
  3.  *                                               *
  4.  *  v1.19 written by Koessi                      *
  5.  *                                               *
  6.  *  05 Oct 94 : added "PRT/K"                    *
  7.  *                                               *
  8.  *  Source Copyright RBF Software                *
  9.  *                                               *
  10.  * use within PD releases encouraged.            *
  11.  * Any alterations may not be released, however, *
  12.  * you are requested to send your ideas on to us *
  13.  *                                               *
  14.  * Shareware/Commercial use requires a licence   *
  15.  *                                               *
  16.  *  this is help showing the usage of            *
  17.  *  "hyper" from inside another program          *
  18.  *                                               *
  19.  *  Compile with DICE:                           *
  20.  *  dcc help.c -ohelp -rr -2.0                   *
  21.  *                                               *
  22.  *************************************************/
  23.  
  24. #include <exec/types.h>
  25. #include <exec/execbase.h>
  26. #include <exec/memory.h>
  27. #include <dos/dos.h>
  28. #include <dos/dostags.h>
  29. #include <rexx/storage.h>
  30.  
  31. /* Prototypes */
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/alib_protos.h>
  35. #include <clib/rexxsyslib_protos.h>
  36.  
  37. #define  MSG struct Message
  38. #define RMSG struct RexxMsg
  39. #define MSGP struct MsgPort
  40. #define SIZE 32
  41.  
  42. extern void SendRxMsg(char *);
  43. extern __stkargs void _main(short, char *);
  44. extern int main(int, char **);
  45.  
  46. #define NUMARGS    13
  47. #define ANSI_COL_2 "\x9B32m"
  48. #define ANSI_RESET "\x9B0m"
  49.  
  50. const char version[]    = "$VER: "
  51.                           "Help 1.19 ("__DATE__") © RBF Software";
  52. const char exthelpstr[] = ANSI_COL_2
  53.                           "\nUsage:\tHelp [FILENAME] [DOC chapter] [SCREEN publicscreen]\n"
  54.                           "\t\t[PRT filename] [X n] [Y n] [WIDTH n] [HEIGHT n]\n"
  55.                           "\t\t[GADS ON|OFF] [FONT name.font<n>] [SLEEP] [QUIT]\n"
  56.                           ANSI_RESET
  57.                           "\n\tcall Hyper's ARexx-port:\n"
  58.                           "\tFILENAME\tshould be a hyper-text-file\n"
  59.                           "\tDOC/K\t\trequest a special chapter\n"
  60.                           "\tSCREEN/K\tmake Hyper appear on that screen\n"
  61.                           "\tPRT/K\t\tsend print output to this (default \"prt:\")\n"
  62.                           "\tX/N, Y/N\n"
  63.                           "\tW=WIDTH/N\n"
  64.                           "\tH=HEIGHT/N\tset position&size for the window\n"
  65.                           "\tG=GADS/T\ttoggle gadgets ON/OFF (default OFF)\n"
  66.                           "\tF=FONT/K\tuse this font to render text\n"
  67.                           "\tonly if Hyper is already running:\n"
  68.                           "\tS=SLEEP/S\tstart Hyper into the background\n"
  69.                           "\tQ=QUIT/S\tend Hyper and free memory\n"
  70.                           "\t\t\t";
  71.  
  72. const char template[]   = "FILENAME,DOC/K,SCREEN/K,PRT/K,X/N,Y/N,W=WIDTH/N,H=HEIGHT/N,"
  73.                           "G=GADS/T,F=FONT/K,S=SLEEP/S,Q=QUIT/S";
  74.  
  75. const char portname[]   = "HYPER_RXPORT";
  76. const char command[]    = "SYS:Utilities/hyper S";    /*  hardcoded path :-| */
  77. const char error[]      = "\n\n"ANSI_COL_2"***ERROR"ANSI_RESET;
  78.  
  79. const void *argarray[NUMARGS] = {0};                  /*  holds argptrs   */
  80.  
  81. char *taskname = &version[6];
  82.  
  83. /*************************************************
  84.  *                                               *
  85.  *                                               *
  86.  *    FUNCTION: _main                            *
  87.  *                                               *
  88.  *                                               *
  89.  *    INPUT:    short len                        *
  90.  *              char *arg                        *
  91.  *                                               *
  92.  *    OUTPUT:   __stkargs void                   *
  93.  *                                               *
  94.  *    NOTE:                                      *
  95.  *                                               *
  96.  *************************************************/
  97.  
  98.  
  99. __stkargs void
  100. _main(short len, char *arg)
  101. {
  102.   PutStr(ANSI_COL_2);
  103.   PutStr(taskname);
  104.   PutStr(ANSI_RESET"\n");
  105.   int errorcode = ERROR_REQUIRED_ARG_MISSING;
  106.   if (len > 1)          /*  args ? */
  107.   {
  108.     struct RDArgs *rdargs;
  109.     if (rdargs = AllocVec(sizeof(struct RDArgs), MEMF_PUBLIC|MEMF_CLEAR))
  110.     {
  111.       rdargs->RDA_ExtHelp = exthelpstr;   /*  shown if 2 x ? */
  112.  
  113.       struct RDArgs *rda;
  114.       if (rda = ReadArgs(template, argarray, rdargs))
  115.       {
  116.         long **argptr = argarray;
  117.         for (BYTE i = 0; i < NUMARGS; ++i)
  118.         {
  119.           if (argptr && *argptr)
  120.           {
  121.             errorcode = RETURN_OK;
  122.             break;
  123.           }
  124.           ++argptr;
  125.         }
  126.         if (errorcode == RETURN_OK)
  127.         {
  128.           MSGP *port;
  129.           if (!(port = FindPort(portname)))
  130.           {
  131.             SystemTags(command, SYS_Asynch, TRUE,
  132.                                 SYS_Output, NULL,
  133.                                 SYS_Input,  NULL,
  134.                                 TAG_DONE);
  135.  
  136.             for (BYTE i = 10; i; --i)
  137.             {
  138.               Delay(20);
  139.               if (port = FindPort(portname))
  140.                 break;
  141.             }
  142.           }
  143.           PutStr("\n");
  144.           if (port)
  145.             SendRxMsg(arg);
  146.           else
  147.             errorcode = ERROR_OBJECT_NOT_FOUND;
  148.         }
  149.         FreeArgs(rda);
  150.       }
  151.       else
  152.         errorcode = IoErr();
  153.  
  154.       FreeVec(rdargs);
  155.     }
  156.     else
  157.       errorcode = ERROR_NO_FREE_STORE;
  158.   }
  159.   if (errorcode)
  160.     PrintFault(errorcode, error);
  161. }
  162.  
  163. /*************************************************
  164.  *                                               *
  165.  *                                               *
  166.  *    FUNCTION: SendRxMsg                        *
  167.  *                                               *
  168.  *                                               *
  169.  *    INPUT:    char *msgtxt                     *
  170.  *                                               *
  171.  *    OUTPUT:   void                             *
  172.  *                                               *
  173.  *    NOTE:     like cmdline                     *
  174.  *                                               *
  175.  *************************************************/
  176.  
  177.  
  178. void
  179. SendRxMsg(char *msgtxt)
  180. {
  181.   MSGP *reply_port;
  182.   if (reply_port = CreateMsgPort())
  183.   {
  184.     void *rx_msg;       /*  casted to parts of a RexxMsg struct */
  185.     if (rx_msg = AllocVec(sizeof(RMSG), MEMF_PUBLIC|MEMF_CLEAR))
  186.     {
  187.       ((struct Node *)rx_msg)->ln_Type      = NT_MESSAGE;
  188.       ((MSG         *)rx_msg)->mn_ReplyPort = reply_port;
  189.       ((MSG         *)rx_msg)->mn_Length    = sizeof(RMSG);
  190.       ((RMSG        *)rx_msg)->rm_Args[0]   = msgtxt;
  191.  
  192.       Forbid();
  193.       MSGP *rx_port;
  194.       if (rx_port = (MSGP *)FindPort(portname))
  195.       {
  196.         PutMsg(rx_port, (MSG *)rx_msg);
  197.         Permit();
  198.         WaitPort(reply_port);
  199.         ReplyMsg(GetMsg(reply_port));
  200.       }
  201.       else
  202.         Permit();
  203.  
  204.       FreeVec(rx_msg);
  205.     }
  206.     DeleteMsgPort(reply_port);
  207.   }
  208. }